import 'package:flutter/material.dart';
import 'package:flutter_demo/models/common_model.dart';
import 'package:flutter_demo/widget/webview.dart';


class LocalNav extends StatelessWidget {
  final List<CommonModel> localNavList;

  LocalNav({@required this.localNavList});

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 300,
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.all(Radius.circular(6)),
        boxShadow: [
          BoxShadow(
            color: Colors.black12,
            blurRadius: 12.0,
          ),
        ],
      ),
      child: Padding(
        padding: EdgeInsets.all(5),
          child: Row(
            children: _itemList(context),
          )
      ),
    );
  }

  List<Widget> _itemList(BuildContext context) {
    List<Widget> list = new List();
    localNavList.forEach((value) {
      list.add(_item(value, context));
    });
    return list;
  }

  Widget _item(CommonModel model, BuildContext context) {
    return Expanded(
      flex: 1,
      child: GestureDetector(
        child: Column(
          children: <Widget>[
            Center(
              child: Image.network(
                model.icon,
                fit: BoxFit.cover,
                width: 40,
                height: 40,
              ),
            ),
            Center(
              child: Text(model.title, style: TextStyle(fontFamily: 'PingFang', fontSize: 10),),
            )
          ],
        ),
        onTap: () {
          Navigator.push(context,
              MaterialPageRoute(
                  builder: (context) => WebView(
                    url: model.url,
                    statusBarColor: model.statusBarColor,
                    hideAppBar: model.hideAppBar,
                  )));

        },
      ),
    );
  }
}
